package com.bw.shop_2302.userlogin

import androidx.lifecycle.viewModelScope
import com.bw.base.entity.LoginEntity
import com.bw.base.entity.Res
import com.bw.base.mvvm.BaseViewModel
import com.bw.shop_2302.utils.SingleLiveData
import com.google.gson.Gson
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody

class UserLoginViewModel:BaseViewModel() {

    var loginsuccess=SingleLiveData<Res<LoginEntity>>()
    var loginfail=SingleLiveData<String>()

    fun userlogin(account:String,password:String){

        viewModelScope.launch {

            try {

                var map= mutableMapOf<String,Any>()
                map["account"]=account
                map["password"]=password

                loginsuccess.postValue(apiServer.Login(mapToBody(map)))


            }catch (e:Exception){


                loginfail.postValue(e.message.toString())

            }
        }





    }
}